﻿using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Windows.Forms;

namespace SatisGonderim
{
    static class Program
    {

        public static DevExpress.LookAndFeel.DefaultLookAndFeel look = new DevExpress.LookAndFeel.DefaultLookAndFeel();

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            AppDomain currentDomain = AppDomain.CurrentDomain;
            currentDomain.UnhandledException += currentDomain_UnhandledException;

            look.LookAndFeel.SkinName = "Black";
            DevExpress.Skins.SkinManager.EnableFormSkins();

            SystemEvents.SessionEnding += SystemEvents_SessionEnding;

            if (!File.Exists(Application.StartupPath + "\\ayarlar.ini"))
            {
                frmAyarlar ayar = new frmAyarlar();
                if (ayar.ShowDialog() == DialogResult.OK)
                    Application.Exit();
            }
            else
            {
                Sessions.Get.OpenSession();

                if (args.Length > 0)
                {
                    Application.Run(new FrmTopluAktarim());
                }
                else
                {
                    Application.Run(new frmMain());
                }
            }

            Sessions.Get.CloseSession();
        }

        static void currentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            Exception ex = (Exception)e.ExceptionObject;
            MessageBox.Show(ex.Message);
        }

        static void SystemEvents_SessionEnding(object sender, SessionEndingEventArgs e)
        {
            System.Environment.Exit(System.Environment.ExitCode);
            Application.Exit();
        }
    }
}
